<template>
    <el-form ref="form" :model="form" label-width="80px">

        <el-form-item label="书名">
            <el-input v-model="form.bookName"></el-input>
        </el-form-item>
        <el-form-item label="剩余数量">
            <el-input v-model="form.bookCounts"></el-input>
        </el-form-item>
        <el-form-item label="详情">
            <el-input v-model="form.detail"></el-input>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="onUpdate">更新</el-button>
            <el-button @click="$router.replace('/body')">取消</el-button>
        </el-form-item>

    </el-form>
</template>

<script>
    import qs from "qs";

    export default {
        name: "Update",
        data(){
            return {
                form:{
                    bookId: this.$route.params.bookId,
                    bookName: this.$route.params.bookName,
                    bookCounts: this.$route.params.bookCounts,
                    detail: this.$route.params.detail
                }
            }
        },
        methods:{
            onUpdate(){
                // console.log(this.form.bookId)
                // console.log(this.form.bookName)
                // console.log(this.form.bookCounts)
                // console.log(this.form.detail)
                const _this = this;
                axios({
                    method: "put",
                    url: "http://127.0.0.1:8088/updateBook",
                    data: qs.stringify(this.form),
                }).then(res => {
                    console.log('/update=>'+res.data);
                    _this.$router.replace("/")
                }).catch(err => {
                    console.log(err)
                })
            }
        }
    }
</script>

<style scoped>

</style>